<?php
/**
 * Created by PhpStorm.
 *
 * Author : Traveler.
 * Time   : 2019/12/16 13:02
 * Company: Inner Mongolia Zhengzhi Network Technology Co., Ltd
 */

namespace app\admin\model;


use app\admin\BaseModel;

class Config extends BaseModel
{
    /**
     * 数据表名称
     * @var string
     */
    protected $table = 'ibms_config';

    /**
     * (静态)获取全部系统配置(数组)
     * @return array
     */
    public static function getAllConfig()
    {
        $config = static::select();
        $result = array_column($config->toArray(), 'value', 'name');

        return $result;
    }

    /**
     * (静态)获取指定名称的配置(数组)
     * @param array $name 配置项名称
     * @return array
     */
    public static function getConfigByName(array $name)
    {
        $config = static::whereIn('name', $name)->select();
        $result = array_column($config->toArray(), 'value', 'name');

        return $result;
    }

    /**
     * (静态)获取指定名称的配置(值)
     * @param string $name 配置项名称
     * @return mixed
     */
    public static function getValueByName(string $name)
    {
        return static::where('name', $name)->value('value');
    }

    /**
     * (静态)获取指定组的配置(数组)
     * @param array $group 配置组名称
     * @return array
     */
    public static function getConfigByGroup(array $group)
    {
        $config = static::whereIn('group', $group)->select();
        $result = array_column($config->toArray(), 'value', 'name');

        return $result;
    }
}